import math

n = int(input())
count = int(math.log(n, 10)) + 1
print(count * 9 + 9)
